const lcRQ = {

  /* 商品分类枚举获取 */
  /* 

    只传入_this， 通用后面封装

    依赖
    
    //商品分类内容
    catCodeOpts: [{ value: "", label: "请选择" }],
    superCodeOpts: [{ value: "", label: "请选择" }],
    classCodeOpts: [{ value: "", label: "请选择" }],

    classCodeShows: {},
    catCodeShows: {},
    superCodeShows: {},
    showPageKey: 101,  //:key="showPageKey"

    监听
    watch:  {
    "formData.catCode"() {
      this.getSort_2();
    },
    "formData.superCode"() {
      this.getSort_3();
    },
  },

  两个方法

  @change="twoSortChangeF"
  //组件封装方法要暴露change
  
  /* 一级分类change * /
  oneSortChangeF() {
    this.formData.superCode = "";
    this.formData.classCode = "";
    this.getSort_2();
  },

  /* 二级分类change * /
  twoSortChangeF() {
    this.formData.classCode = "";
    this.getSort_3();
  },

    //刷新
    refreshF() {
      this.showPageKey = this.tools.getRandomStr();
    },

    //一级分类
    getSort_1 (){
      this.tools.getSort_1({_this: this})
    },
    //二级分类
    getSort_2 (){
      this.tools.getSort_2({_this: this})
    },
    //三级分类
    getSort_3 (){
      this.tools.getSort_3({_this: this})
    },

  */
  getGoodsSortOptsF({
    _this,
  }) {

    lcRQ.getSort_1({ _this });
    lcRQ.getSort_2({ _this });
    lcRQ.getSort_3({ _this });

  },


  //一级分类获取
  getSort_1({ _this }) {
    var url = _this.api.jd_sort_m.page;
    var data = {
      pageIndex: 1,
      pageSize: 10000,
      // "catCode": _this.formData.catCode,
      classType: "1",
    };

    _this.tools.post(
      url,
      data,
      null,
      (res) => {

        if (res.code == 200) {
          var opts = _this.catCodeOpts ? _this.catCodeOpts : [];
          var records = res.data.records || res.data || [];
          records.forEach((item, index) => {
            opts.push({
              label: item.className + "",
              value: item.classCode + "",
            });
            //展示字段
            if (_this.catCodeShows) {
              _this.catCodeShows[item.classCode + ""] = item.className;
            }
          });
          _this.catCodeOpts = opts;
          _this.refreshF();
        } else {
          _this.$message({
            type: "warning",
            message: res.message,
          });
        }
      },
      (err) => {
        console.log(err);
      }
    );
  },

  //二级分类获取
  getSort_2({ _this }) {
    var url = _this.api.jd_sort_m.page;
    var data = {
      pageIndex: 1,
      pageSize: 10000,
      catCode: _this.formData.catCode,
      classType: "2",
    };

    _this.tools.post(
      url,
      data,
      null,
      (res) => {

        if (res.code == 200) {
          //清空
          _this.superCodeOpts = [{ value: "", label: "请选择" }];
          var opts = _this.superCodeOpts ? _this.superCodeOpts : [];

          var records = res.data.records || res.data || [];
          console.log(_this.superCodeOpts);
          records.forEach((item, index) => {
            opts.push({
              label: item.className + "",
              value: item.classCode + "",
            });
            //展示字段
            if (_this.superCodeShows) {
              _this.superCodeShows[item.classCode] = item.className;
            }
          });
          if (_this.formData.catCode) {
            _this.superCodeOpts = opts;
          }
          _this.refreshF();
        } else {
          _this.$message({
            type: "warning",
            message: res.message,
          });
        }
      },
      (err) => {
        console.log(err);
      }
    );
  },

  //三级分类获取
  getSort_3({ _this }) {
    var url = _this.api.jd_sort_m.page;
    var data = {
      pageIndex: 1,
      pageSize: 10000,
      superCode: _this.formData.superCode,
      classType: "3",
    };

    _this.tools.post(
      url,
      data,
      null,
      (res) => {
        if (res.code == 200) {
          //清空
          _this.classCodeOpts = [{ value: "", label: "请选择" }];
          var opts = _this.classCodeOpts ? _this.classCodeOpts : [];
          var records = res.data.records || res.data || [];
          records.forEach((item, index) => {
            opts.push({
              label: item.className + "",
              value: item.classCode + "",
            });
            //展示字段
            if (_this.classCodeShows) {
              _this.classCodeShows[item.classCode] = item.className;
            }
          });
          if (_this.formData.superCode) {
            _this.classCodeOpts = opts;
          }
          _this.refreshF();
        } else {
          _this.$message({
            type: "warning",
            message: res.message,
          });
        }
      },
      (err) => {
        console.log(err);
      }
    );
  },



}

export default lcRQ;